Skip to content

Wait up to two seconds for input device to become available. - #215

Merged
sezanzeb merged 1 commit into
gvalkov:mainfrom
KarsMulder:main
Apr 1, 2024
Merged

sezanzeb merged 1 commit into
gvalkov:mainfrom
KarsMulder:main

Conversation

@KarsMulder

Copy link
Copy Markdown
Contributor

It has been reported in issue #214 that even on modern Linux distributions that use devtmpfs, it can take longer than 0.1 seconds before the input device becomes available with the right permissions.

To solve this: if sysfs reports that a specific input device should be used, but it cannot be opened immediately, keep trying again for up to two seconds.

This only adjusts the _find_device_linux function, because adding such a loop to _find_device_fallback runs at risk of causing issue #205 again on outdated operating systems: if the sought device is not readable yet, but another device with the same name already exists, then there is a risk that we open the other device with the same name instead of the intended one.

(Unless _find_device_fallback refuses to return a device if another device with a higher event number is still unreadable. But that goes another layer deeper into "I do not have the proper environment to test this", so I've refrained from implementing that.)

A sporadic error of "sometimes the wrong device is opened when the system is under heavy load" is even harder to debug than a sporadic error of "sometimes no device is opened at all when the system is under heavy load".

The function _find_device_linux does not risk returning the wrong device because sysfs can immediately tell us exactly which device we need, even if the that input device doesn't have the right permissions yet.

It has been reported that even on modern Linux distributions that use
devtmpfs, it can take longer than 0.1 seconds before the input device
becomes available with the right permissions. If sysfs reports that a
specific input device should be used, but it cannot be opened
immediately, keep trying again for up to two seconds.
@sezanzeb

sezanzeb commented Apr 1, 2024

Copy link
Copy Markdown
Collaborator

Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants